<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 劳寄修
  Date: 2021/2/13
  Time: 21:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>借出</title>
      	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/tips.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/popper.min.js"></script>
   	<style>
        *{

            margin:0px;
            padding: 0px;
        }

        .toast-center-center {
            top: 50%;
            left: 50%;
            margin-top: -30px;
            margin-left: -150px;
        }

    </style>
</head>
<body>

<div class="container shadow-sm p-3 mb-5 bg-white rounded">
	<div class="row">
		<div class="col-12 col-md-12">
			<input id="inputSub" type="text" style="width: 250px;"  class="form-control border-info float-left rounded-right rounded-0 order-0"/>
			<button id="btn-sub" type="button" class="btn btn-info rounded-0">搜索设备</button>
			<button type="button" id="refreshData" class="btn bg-info rounded-0 text-white"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
				<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
				<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
			</svg>刷新</button>
			<button id="delBtn" class="btn btn-info rounded-0"><!--删除按钮  -->
				<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
					<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
					<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
				</svg>删除
			</button>
		</div>
	</div>


	<div class="row">
		<div class="col-md-12 col-md-12">
			<div id="tba" >

				<table id="myTable" style="table-layout:fixed;"></table>
			</div>
		</div>
	</div>
</div>

</body> 

    <script>
        var $table= $("#myTable");
        var path="${pageContext.request.contextPath}/lr/lrparams";
        var val="";


        $(function () {
            $('.dropdown-toggle').dropdown();
            $table.bootstrapTable(temp);
            $("#btn-sub").click(function () {
                val=$("#inputSub").val();
                $table.bootstrapTable('destroy');
                $table.bootstrapTable(temp);
                $(".fixed-table-container").hide();
             });


			//刷新界面
            $("#refreshData").click(function (){
				window.parent.frames.detailed("/pj/lend");
			});



            delLRParam();
            //垂直居中
            customTips();
            $(".fixed-table-container").hide();
        });

        var temp={
            striped:false,//隔行变色
            method:'get',//请求格式
            url:path,//请求地址
            pageNumber : 1, //初始化加载第一页
            pagination : true,//是否分页
            contentType:'application/x-www-form-urlencoded; charset=UTF-8',
            sidePagination : 'client',//server:服务器端分页|client：前端分页
            pageSize : 3,//单页记录数
            pageList : [4,6],//可选择单页记录数
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            toolbar:'#myTable',//容器
            queryParams:function (params) {
                var temp={
                    limit : params.limit, // 每页显示数量
                    offset : params.offset, // SQL语句起始索引
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    param:val,
                }
                return temp;
            },
            columns:[
                {

                    title:'id',
                    checkbox:true,//显示多选
                    name:'ck',
                    align:'center'
                }, {
                    title:'eid',
                    align:'center',
                    field:"eID",
                    visible:false,
                }, {
                    title:'序号',
                    align:'center',
                    file:"rowindex",
                    formatter:function (value, row, index) {
                        //value：该cell本来的值，row：该行数据，index：该行序号（从0开始）
                        return index+1;
                    }
                }, {
                    title:'设备名',
                    field:'eName',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'类型',
                    field:'etype',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'品牌',
                    field:'brand',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'型号',
                    field:'model',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'经办人',
                    field:'ggent',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'申请人',
                    field:'borrower',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'借用数量',
                    field:'lendNum',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'借用部门',
                    field:'dpt',//该列映射的data的参数名
                    align:'center',

                }, {
                    title:'借出时间',
                    field:'st',//该列映射的data的参数名
                    align:'center',

                }
            ]


        }
        
        


        
        //删除功能
        function delLRParam() {
            $("#delBtn").click(function () {
                var url="${pageContext.request.contextPath}/lr/del";
                var ids=$.map($table.bootstrapTable("getSelections"),function (row) {
                    return row.eID;
                });

                var arr= Object.values(ids);
                if (ids.length>0){

                    $.ajax({
                        type:"get",
                        url:url,
                        dataType:"json",
                        traditional: true,
                        contentType: "application/json",
                        data:{"param":JSON.stringify(arr)},
                        success:function (obj) {
                            if (obj.state){
                                toastr.success("删除成功");
                                $table.bootstrapTable('remove',{field:'eID',values:ids})
                            }else{
                                toastr.error("删除失败");
                            }
                        },
                        erorr:function (obj) {
                            toastr.error("删除失败");
                        }

                    });

                }else{
                    toastr.warning("请选择行");
                }
            });


        }
 
    </script>
</html>
